package com.pactera.asmp.server.restfullapi;

import com.pactera.asmp.server.common.constants.PermissionCode;
import com.pactera.asmp.server.entity.ResponseResult;
import com.pactera.asmp.server.entity.TaskDtoV2;
import com.pactera.asmp.server.service.TaskServiceV2;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v2/task")
public class RestfullTaskApiV2 {

    private static final Logger logger = LoggerFactory.getLogger(RestfullTaskApiV2.class);

    @Autowired
    private TaskServiceV2 taskService;
//
//    @Autowired
//    private ScreenDataService screenDataService;
//
    @RequiresPermissions({PermissionCode.TEST_TASK})
    @PostMapping
    public ResponseResult createTask(@RequestBody @Validated TaskDtoV2 taskDtoV2){
        logger.info("POST /api/v1/task createTask");
        return taskService.createTask(taskDtoV2);
    }


//    @RequiresPermissions({PermissionCode.TEST_TASK})
//    @GetMapping
//    public ResponseResult getTaskList(@RequestParam("projectId") Integer projectId,@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum
//            ,@RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize) {
//        logger.info("GET /api/v1/task  getTaskList");
//        TaskSearchDTO searchDTO = new TaskSearchDTO(null,projectId,null,null,null,null,null,null);
//        searchDTO.setPageNum(pageNum);
//        searchDTO.setPageSize(pageSize);
//        return ResponseResult.defaultSuccess(taskService.getTaskList(searchDTO));
//    }
//
//    @GetMapping(value = "/scripts/{taskId}")
//    public ResponseResult<List<ScriptInfo2>> getTaskScriptInfo(@PathVariable("taskId") Integer taskId) {
//        logger.info("GET /api/v1/task/scripts/{}",taskId);
//        List<ScriptInfo2> taskScriptInfo = taskService.getTaskScriptInfo(taskId);
//        return ResponseResult.defaultSuccess(taskScriptInfo);
//    }
//

//
//    @RequiresPermissions({PermissionCode.TEST_TASK})
//    @PostMapping(value = "/reset")
//    public ResponseResult resetTaskSchedule(@RequestBody @Validated TaskDTO taskDTO) throws Exception {
//        logger.info("POST /api/v1/task/reset resetTaskSchedule");
//        return taskService.resetTaskSchedule(taskDTO);
//    }
//
//    @RequiresPermissions({PermissionCode.TEST_TASK})
//    @PutMapping(value = "/cancel/{id}",  produces = "application/json;charset=UTF-8")
//    public ResponseResult cancelTask(@PathVariable("id") Integer id) {
//        logger.info("PUT /api/v1/task/cancel/{}" ,id);
//        return taskService.cancelTask(id);
//    }
//
//    @GetMapping(value = "/taskIng")
//    public ResponseResult getTaskingByProjectId(@RequestParam("projectId") Integer projectId,@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum
//            ,@RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize) {
//        logger.info("GET /api/v1/task  getTaskingByProjectId");
//        TaskSearchDTO searchDTO = new TaskSearchDTO(null,projectId,null,null,null,null,null,null);
//        searchDTO.setPageNum(pageNum);
//        searchDTO.setPageSize(pageSize);
//        return ResponseResult.defaultSuccess(screenDataService.getTaskingByProjectId(searchDTO));
//    }
//
//    @GetMapping(value = "/detail")
//    public ResponseResult getTaskById(@RequestParam("taskId") Integer taskId) {
//        logger.info("GET /api/v1/task/detail: {}",taskId);
//        return ResponseResult.defaultSuccess(taskService.getTaskById(taskId));
//    }
}
